/*
 * LightFence.cpp
 *
 *  Created on: Jan 2, 2009
 *      Author: Carmine Red
 */

#include "LightFence.h"

LightFence::LightFence()
{
}

void LightFence::cleanUp()
{
	//to do
}

void LightFence::setAnchorOne(AnchorPoint* toUse)
{
	anchor1 = toUse;
}

void LightFence::setAnchorTwo(AnchorPoint* toUse)
{
	anchor2 = toUse;
}

void LightFence::render()
{
	//drawwwwwwww
}

/*
NOTE:
This is how we'll go through comparing the game characters (enemies) to the light
fences: first we'll check if the light fence is active.

If one is, then we'll run through each game character and check if it is within
range of the fence.

If it is, then we'll set/update their status with regards to whether they're above
or below the fence. There are two conditions possible: above or below.

THIS STATUS INFO WILL BE KEPT ON THE LIGHTFENCE, NOT THE ENEMY.

IF the checkAttack property is false (meaning the fence was previously inactive),
then we set it to active and we'd normally be done with the checking process.
	OTHERWISE we're allowed to check if there were any changes. We'll cycle through
		the changes.
		IF there were thing that crossed, we then choose the target(s), deal the
		damage, set the cooldown to start counting down again, and erase our enemy
		status memory.
*/
void LightFence::update()
{
	//updaaaaate
}

/*
This function returns whether a game character is close enough to the light fence to
care about checking it
*/
bool LightFence::isInRange(int xLoc, int yLoc)
{
	int xHigh, xLow;
	int yHigh, yLow;
	if(anchor1->getxPos() > anchor2->getxPos())
	{
		xHigh = anchor1->getxPos();
		xLow = anchor2->getxPos();
	}
	else
	{
		xHigh = anchor2->getxPos();
		xLow = anchor1->getxPos();
	}

	if(anchor1->getyPos() > anchor2->getyPos())
	{
		yHigh = anchor1->getyPos();
		yLow = anchor2->getyPos();
	}
	else
	{
		yHigh = anchor2->getyPos();
		yLow = anchor1->getyPos();
	}

	// if xLoc is within the two anchor x's,
	// and yLoc for the two anchor y's return true
	if(xLoc <= xLow && xLoc >= xHigh && yLoc <= yLow && yLoc >= yHigh)
	{
		return true;
	}
	return false;
}

/*
This function return whether a game character is on one side of the light fence
(above, or true) or the other side (below, or false).
This is important because it is used to determine whether a game character has
crossed the fence and may take damage.
*/
bool LightFence::isAbove(int xLoc, int yLoc)
{
	AnchorPoint* leftAnchor;
	AnchorPoint* rightAnchor;

	if(anchor1->getxPos() <= anchor2->getxPos())
	{
		leftAnchor = anchor1;
		rightAnchor = anchor2;
	}
	else
	{
		leftAnchor = anchor2;
		rightAnchor = anchor1;
	}

	if(yLoc >=
			(
			leftAnchor->getyPos() +
				(xLoc - leftAnchor->getxPos()) *
				(rightAnchor->getyPos() - leftAnchor->getyPos()) /
				(rightAnchor->getxPos() - leftAnchor->getxPos())
			)
		)
	{
		return true;
	}
	else
	{
		return false;
	}
}

/*
returns whether the light fence is active or not by checking the countdown against 0;
*/
bool LightFence::isActive()
{
	return (currentCooldown == 0);
}

void LightFence::triggerDamage()	// this makes the fence act as if it caused damage and all the
						// other stuff that comes with it
{
}
